package im.starchat.chat.utils;

/**
 * @author liuchao
 *         json数据保存这里
 */
public class JsonSD {

    private static final String JSON_FILE_PATH = "/.json";

    public static enum CATEGORY {
        COLLECTION_LIST,
        FILTER_LIST,
        MAIN_BANNER,
        MAIN_LIST
    }

    private static String getFilePath(CATEGORY category) {
        if (FileUtils.isSDCardMounted()) {
            return FileUtils.SDPATH + JSON_FILE_PATH + "/" + category.name();
        }
        return "";
    }

    public static void writeJsonToFile(CATEGORY category, String json) {
        if (FileUtils.isSDCardMounted()) {
            FileUtils.writeToFileFromString(getFilePath(category), json);
        }
    }

    public static String getJsonFromFile(CATEGORY category) {
        if (FileUtils.isFileExists(getFilePath(category))) {
            return FileUtils.readStringFromFile(getFilePath(category));
        } else {
            return "";
        }
    }

    /**
     *读取本地默认json
     * @param context
     * @return
     */
//    public static String readTabJson(Context context){
//        String json = null;
//        try{
//            InputStream is = context.getResources().openRawResource(R.raw.tab);
//            byte [] buffer = new byte[is.available()] ;
//            is.read(buffer);
//
//            json = new String(buffer,"utf-8");
//        }catch (Exception e){}
//        return json;
//    }

}
